package chain.leave;

public abstract class Handler {

	/** 处理者姓名 */
	private String name;

	/** 下一个处理者 */
	private Handler nextHandler;

	/** 处理请假 */
	public abstract void process(LeaveRequest request);

	public Handler(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Handler getNextHandler() {
		return nextHandler;
	}

	public void setNextHandler(Handler nextHandler) {
		this.nextHandler = nextHandler;
	}
}

/**
 * 
 * 主管
 *
 */
class Director extends Handler {

	public Director(String name) {
		super(name);
	}

	@Override
	public void process(LeaveRequest request) {

		if (request.getNumOfDays() <= 5) {
			System.out.println(this.getName() + "批准请假，请假天数" + request.getNumOfDays());
		} else {
			this.getNextHandler().process(request);
		}
	}
}

/**
 *
 * 经理
 *
 */
class Manager extends Handler {

	public Manager(String name) {
		super(name);
	}

	@Override
	public void process(LeaveRequest request) {
		if (request.getNumOfDays() > 5 && request.getNumOfDays() <= 10) {
			System.out.println(this.getName() + "批准请假，请假天数" + request.getNumOfDays());
		} else {
			this.getNextHandler().process(request);
		}
	}
}

/**
 * 
 * 总经理
 *
 */
class TopManager extends Handler {

	public TopManager(String name) {
		super(name);
	}

	@Override
	public void process(LeaveRequest request) {
		if (request.getNumOfDays() >= 10) {
			System.out.println(this.getName() + "批准请假，请假天数" + request.getNumOfDays());
		}
	}

}